home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol04 / 03 / vmm / vm.h < prev   
C/C++ Source or Header  |  1989-01-10  |  3KB  |  105 lines

  1.  
  2. /*******************************************************************/
  3. /* Virtual Memory Manager          VM.H                            */
  4. /*                                                                 */
  5. /* (C) Copyright 1988  Marc Adler/Magma Systems-All Rights Reserved*/
  6. /*                                                                 */
  7. /* This software is for personal use only, and may not be used in  */
  8. /* any commercial product, nor may it be sold in any way.          */
  9. /*                                                                 */
  10. /*******************************************************************/
  11.  
  12. #define NO              0
  13. #define YES             1
  14.  
  15. #define MAXSLOTS        1024
  16. #define PAGESIZE        4096
  17. #define EMM_PAGESIZE    16384
  18. #define MAXPATHLEN      65
  19.  
  20. typedef unsigned PAGEID;
  21. typedef unsigned long HANDLE;
  22.  
  23.  
  24. /*
  25.    The page header ....
  26. */
  27. typedef struct page
  28. {
  29.   struct page *next;            /* chain to next free page in list */
  30.   char far *memaddr;            /* memory address of the page block */
  31.   unsigned long diskaddr;       /* disk address of the page block */
  32.   PAGEID   id;                  /* page identifier */
  33.   unsigned long LRUcount;       /* least-recently-used count      */
  34.   unsigned pagesize;            /* how many bytes is this page    */
  35.   unsigned freebyte;            /* index of 1st free byte in page */
  36.   unsigned bytesfree;           /* # of bytes free in this page   */
  37.   unsigned maxcontigfree;       /* max # of contiguous free bytes */
  38.  
  39.   unsigned flags;
  40. #define PAGE_IN_MEM     0x0001
  41. #define PAGE_ON_DISK    0x0002
  42. #define IS_DIRTY        0x0004
  43. #define SET_PAGE_DIRTY(p)        ((p)->flags |= IS_DIRTY)
  44. #define NON_SWAPPABLE   0x0008
  45. #define PAGE_IN_EMM     0x0010
  46. } PAGE;
  47.  
  48.  
  49. typedef struct disktable
  50. {
  51. #define SECTOR_FREE ((PAGE *) NULL)
  52.   PAGE     *page;
  53. } PAGE_DISK_ENTRY;
  54.  
  55.  
  56. /*
  57.    The free block header .....
  58. */
  59. typedef struct freeinfo
  60. {
  61.   unsigned nextfree;  /* offset of next free entry (0xFFFF at end) */
  62.  
  63. #define FREELIST_END  0xFFFF
  64.  
  65.   unsigned bytesfree; /* # of bytes in this chunk */
  66. } FREEINFO;
  67.  
  68.  
  69. /*
  70.   This contains info about the swap file...
  71. */
  72. typedef struct vmfile
  73. {
  74.   char filename[MAXPATHLEN];    /* name of the VM file */
  75.   int  fd;                      /* file handle to the VM file */
  76.   PAGE_DISK_ENTRY slottable[MAXSLOTS];
  77. } VMFILE;
  78.  
  79.  
  80. /* External declarations */
  81. extern char     VMInitialized;
  82. extern unsigned TotalPages;
  83. extern PAGE     *PageList;
  84. extern VMFILE   VMFile;
  85. extern unsigned VMPageSize;
  86.  
  87. /*global*/  int VMInit(void);
  88. /*global*/  int VMTerminate(void);
  89. /*global*/  char *AllocPageText(struct page *, unsigned int );
  90. /*global*/  struct page *AllocPage(void);
  91. /*global*/  int ReadPage(struct page *);
  92. /*global*/  int WritePage(struct page *);
  93. /*global*/  int SwapoutPage(struct page *,int );
  94. /*global*/  int SwapinPage(struct page *);
  95. /*global*/  struct page *FindLRUPage(void);
  96. /*global*/  int FindSlotFree(void);
  97. /*global*/  HANDLE MyAlloc(unsigned int );
  98. /*global*/  void MyFree(HANDLE);
  99. /*global*/  struct page *FindNBytesFree(unsigned int );
  100. /*global*/  struct page *FindNContigBytesFree(unsigned int );
  101. /*global*/  int CompactifyPage(struct page *);
  102. /*global*/  char far *MemDeref(HANDLE);
  103. /*global*/  PAGE *PageDeref(HANDLE);
  104. /*global*/  char *mymalloc(unsigned);
  105.